<?php
	class Sub extends Model_Abstract{
		
		public function add($pubId, $name){
			try{
				if(empty($name)){
					$name = 'Default';
				}
				$sql = "insert into subs set pub_id=?, name=?";
				$reuslt = $this->_connection->execute($sql, array($pubId, $name));
				return $reuslt;
			}
			catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getSubByPubId($pid){
			try{
				$sql = 'select id, name from subs where pub_id=?';
				$result = $this->_connection->query($sql, array($pid));
				return $result;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getAllSubs(){
			try{
				$sql = 'select * from subs';
				$result = $this->_connection->query($sql);
				return $result;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
	}